<template>
	<view>
		<navbar :isback="true" :title="title"></navbar>
		<u-sticky bgColor="#fff" v-if="poplist.length>0" customNavHeight="44">
			<!-- <u-status-bar></u-status-bar> -->
			<view class="tab">
				<u-tabs :list="poplist" lineWidth="118rpx" lineHeight='10rpx' lineColor="#0381FC" :activeStyle="{
				            color: '#1E1E1E',
				            fontWeight: 'bold',
				            transform: 'scale(1.15)'
				        }" :inactiveStyle="{
				            color: '#1E1E1E',
				            transform: 'scale(1)'
				        }" itemStyle="padding-left: 30rpx; padding-right: 30rpx; height: 50rpx;font-size:26rpx;" @click="clicktab">
				</u-tabs>
			</view>
		</u-sticky>
		<u-loading-page icon-size="100rpx" :loading="loading" loading-text="驼乡生活信息超市"></u-loading-page>
		<view class="" v-if="!loading">
			<view class="msglist" v-if="msglist.length>0">
				<!-- <msgitem v-for="(item,index) in msglist" :key="index" :item="item"></msgitem> -->
				<view class="msgitem" @click="to('/pages/msg/detail?id='+item.id)" v-for="(item,index) in msglist"
					:key="index">
					<view class="msgitem__top">
						<view class="u-flex u-flex-y-center">
							<u-avatar :src="URL(item.avatar)" shape="circle" size="57rpx" mode="aspectFill"></u-avatar>
							<view class="msgitem__nickname">
								{{item.contract}}
							</view>
							<view class="msgitem__zd" v-if="item.type==2">
								置顶
							</view>
						</view>
						<view class="u-flex u-flex-y-center">
							<view class="msgitem__tag" v-if="item.category_name">
								{{item.category_name}}
							</view>
							<view class="msgitem__tag" v-if="item.is_other==2">
								其他信息
							</view>
							<view @click.stop="callphone(item.phone)">
								<u-icon name="/static/msg/mobile.png" size="62rpx"></u-icon>
							</view>
						</view>
					</view>
					<view class="msgitem__content">
						{{item.text}}
					</view>
					<view class="msgitem__piclist" v-if="item.imags.length>0">
						<u-album :urls="item.imags" multipleSize='222rpx' singleSize='222rpx'
							singleMode='aspectFill'></u-album>
					</view>
					<view class="u-flex u-flex-y-center u-flex-between">
						<view class="msgitem__time">
							{{$u.timeFormat(item.createtime, 'yyyy-mm-dd hh:MM')}}
						</view>
						<view class="u-flex u-flex-y-center">
							<view class="u-flex u-flex-y-center">
								<u-icon name="/static/msg/ll.png" color="#1A1A1A" size="40rpx"
									imgMode='widthFix'></u-icon>
								<view class="msgitem__num">
									{{item.view}}
								</view>
							</view>
							<view class="u-flex u-flex-y-center">

								<button open-type="share" @click.stop.prevent="prevent(item)"
									style="width: 33rpx;height: 33rpx;background-color: transparent;padding: 0;border: 0;">
									<u-icon name="/static/msg/fx.png" color="#1A1A1A" size="33rpx"></u-icon>
								</button>
								<view class="msgitem__num">
									{{item.share}}
								</view>
							</view>
							<view class="u-flex u-flex-y-center" @click.stop="dianz(item,index)">

								<view class="">
									<u-icon name="/static/msg/sc.png" v-if="!item.isCollect" color="#1A1A1A"
										size="34rpx" imgMode='widthFix'></u-icon>
									<u-icon name="/static/msg/ysc.png" v-else color="#E8BF05" size="34rpx"
										imgMode='widthFix'></u-icon>
								</view>
								<view class="msgitem__num">
									{{item.collect}}
								</view>
							</view>
						</view>
					</view>

				</view>
			</view>
			<view class="" v-else style="padding-top: 50rpx;">
				<u-empty mode="list" text="暂无信息">
				</u-empty>
			</view>
		</view>

		<u-safe-bottom></u-safe-bottom>
		<view class="kf">
			<button class="u-reset-button" open-type="contact">
				<image src="/static/xishi/kf.png" class="kficon" mode=""></image>
			</button>
		</view>
	</view>
</template>

<script>
	import {
		BASE_URL
	} from '@/api/config';
	import home from '@/api/_home.js'
	export default {
		data() {
			return {
				title: '',
				poplist: [],
				msglist: [],
				loading: true
			};
		},
		onLoad(o) {
			this.title = o.title
			if (o.is_other == 2) {
				home.infoList({
					is_other: 2,
					status: 2
				}).then(res => {
					if (res.data.code == 1) {
						this.msglist = res.data.data
						this.loading = false
						this.msglist.map(t => {
							t.imags = []
							t.imag = t.ad_images.split(',')
							if (t.imag[0] == '') {
								t.imag = []
							}
							t.imag.map(t1 => {
								t.imags.push(BASE_URL + t1)
							})
						})
						this.$forceUpdate()
					}
				})
				return
			}
			home.category({
				pid: o.id,
				
			}).then(res => {
				if (res.data.code == 1) {
					this.poplist = res.data.data
					if (this.poplist.length > 0) {
						// 有下一级分类
						this.getlist(this.poplist[0].id)
					} else {
						this.getlist(o.id)
					}
					// this.$store.commit('getcategorylist',res.data.data)
				}
			})
		},
		methods: {
			getlist(category_id) {
				home.infoList({
					category_id,
					status: 2,
					topSort:1
				}).then(res => {
					if (res.data.code == 1) {
						this.msglist = res.data.data
						this.loading = false
						this.msglist.map(t => {
							t.imags = []
							t.imag = t.ad_images.split(',')
							if (t.imag[0] == '') {
								t.imag = []
							}
							t.imag.map(t1 => {
								t.imags.push(BASE_URL + t1)
							})
						})
						this.$forceUpdate()
					}
				})
			},
			clicktab(e) {
				this.getlist(e.id)
			},
			dianz(item, index) {
				item.isCollect = !item.isCollect
				home.infoCollect({
					id: item.id
				}).then(res => {
					uni.$u.toast('操作成功')
				})
				if (item.isCollect) {
					item.collect++
				}
				if (!item.isCollect) {
					item.collect--
				}
				// this.$emit('dianz', this.isCollect)
				this.$forceUpdate()
			},
			prevent(item) {
				// console.log(item)
				this.item = item
			},
		},
		
	}
</script>

<style lang="scss">
	.tab {
		padding: 30rpx 0 20rpx;
	}

	.msgitem {
		padding: 38rpx 20rpx 30rpx 30rpx;
		border-bottom: 2rpx solid #F4F6F8;
		background-color: #fff;

		&__top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-right: 10rpx;
		}

		&__nickname {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 26rpx;
			color: #5A5A5A;
			line-height: 26rpx;
			margin: 0 8rpx;
		}

		&__zd {
			padding: 0 9rpx;
			height: 36rpx;
			background: #E1BC13;
			border-radius: 18rpx 18rpx 18rpx 0rpx;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 22rpx;
			color: #7A3807;
			line-height: 36rpx;
		}

		&__tag {
			padding: 0 10rpx;
			height: 47rpx;
			background: #F7F7F9;
			border-radius: 8rpx;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 25rpx;
			color: #4E4D52;
			line-height: 47rpx;
			margin-right: 15rpx;
		}

		&__content {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #2C2A2A;
			line-height: 40rpx;
			padding: 14rpx 0 20rpx;
		}

		&__piclist {
			margin-bottom: 40rpx;
		}

		&__time {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 24rpx;
			color: #5A5A5A;
			line-height: 24rpx;
		}

		&__num {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 24rpx;
			color: #3C3C3C;
			line-height: 24rpx;
			margin: 0 50rpx 0 12rpx;
		}
	}
</style>